var e = require("../../@babel/runtime/helpers/interopRequireDefault"), t = require("../../@babel/runtime/helpers/createForOfIteratorHelper"), a = e(require("../../@babel/runtime/regenerator")), n = require("../../@babel/runtime/helpers/asyncToGenerator"), i = e(require("../../http/vipCenterApi")), r = e(require("../../http/info")), o = require("../../utils/switchTab"), l = require("../../utils/tool"), s = new i.default(), u = new r.default(), f = getApp();

Page({
    data: {
        topADList: [],
        mainADList: [],
        vipInfo: {},
        vipLevelList: [],
        loginInfo: {}
    },
    onShow: function() {
        (0, o.switchToTab)(this, 2), this.getData(), f.global.isLogin() && this.setVipLevel();
    },
    getData: function() {
        var e = this;
        return n(a.default.mark(function t() {
            var n, i;
            return a.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return n = [ s.topAD(), s.mainAD() ], t.next = 3, Promise.allSettled(n);

                  case 3:
                    i = t.sent, e.setTopAD(i[0]), e.setMainAD(i[1]);

                  case 6:
                  case "end":
                    return t.stop();
                }
            }, t);
        }))();
    },
    setTopAD: function(e) {
        "fulfilled" == e.status ? this.setData({
            topADList: e.value.data
        }) : (0, l.toastToPage)(e.reason.msg);
    },
    setMainAD: function(e) {
        "fulfilled" == e.status ? this.setData({
            mainADList: e.value.data
        }) : (0, l.toastToPage)(e.reason.msg);
    },
    actItemOnTap: function(e) {
        var t = e.currentTarget.dataset.data;
        f.bannerOnTap(t);
    },
    getLoginInfo: function() {
        var e = this;
        return n(a.default.mark(function t() {
            var n;
            return a.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return t.next = 2, u.getUmsMemberInfo();

                  case 2:
                    n = t.sent, e.setData({
                        loginInfo: n.data
                    });

                  case 4:
                  case "end":
                    return t.stop();
                }
            }, t);
        }))();
    },
    setVipLevel: function() {
        var e = this;
        return n(a.default.mark(function n() {
            var i, r, o, l, c, p, v;
            return a.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    if (f.global.isLogin()) {
                        a.next = 2;
                        break;
                    }
                    return a.abrupt("return");

                  case 2:
                    return a.next = 4, s.vipLevel();

                  case 4:
                    return i = a.sent, a.next = 7, u.getUmsMemberInfo();

                  case 7:
                    if (r = a.sent, e.setData({
                        vipLevelList: i.data,
                        loginInfo: r.data
                    }), o = 0, l = "", e.data.loginInfo.vipLevel == e.data.vipLevelList.length) o = 100, 
                    l = "恭喜您成为至尊会员！"; else {
                        c = t(e.data.vipLevelList);
                        try {
                            for (c.s(); !(p = c.n()).done; ) (v = p.value).maxValue = v.maxValue ? v.maxValue : 1 / 0, 
                            e.data.loginInfo.growthValue >= v.miniValue && e.data.loginInfo.growthValue <= v.maxValue && e.data.loginInfo.vipLevel != v.vipLevel && (o = 100, 
                            l = "您将于下一个20号升级为V".concat(v.vipLevel)), e.data.loginInfo.growthValue < v.miniValue && e.data.loginInfo.vipLevel + 1 == v.vipLevel && (o = 100 * parseFloat(e.data.loginInfo.growthValue / v.miniValue), 
                            l = "还差".concat(v.miniValue - e.data.loginInfo.growthValue, "成长值升级VIP").concat(v.vipLevel));
                        } catch (e) {
                            c.e(e);
                        } finally {
                            c.f();
                        }
                    }
                    e.setData({
                        vipInfo: Object.assign(e.data.loginInfo, {
                            percentage: o,
                            levelText: l
                        })
                    });

                  case 13:
                  case "end":
                    return a.stop();
                }
            }, n);
        }))();
    }
});